package org.internna.ossmoney.mvc;

import org.internna.ossmoney.model.security.UserDetails;
import org.springframework.ui.ModelMap;
import org.springframework.util.CollectionUtils;
import org.springframework.stereotype.Controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/financial/dashboard/**")
public class DashboardController {

	@Autowired private AccountController accountController;

    @RequestMapping
    public String index(ModelMap modelMap) {
    	UserDetails user = UserDetails.findCurrentUser();
    	if (CollectionUtils.isEmpty(user.getAccounts())) {
    		return accountController.index(modelMap);
    	} else {
	    	modelMap.addAttribute("dashboard", user.getDashboard());
	        return "dashboard/index";
    	}
    }

}
